﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;

/// <summary>
/// 商家信息
/// </summary>
public partial class Admin_SMSmarketing : AdminPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ValidatorSet validator = new ValidatorSet("Admin");
        validator.SetValidator();
        if (!IsPostBack)
        {
            WebUtility.SetDDLCity(DDLArea);

        }
    }

    /// <summary>
    /// 保存商家
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btSave_Click1(object sender, EventArgs e)
    {
        string msg = tbspecial.Text;
        if (msg.Length == 0)
        {
            AlertScript.AjaxRegisterScript("hideload_super();alert('请输入短信内容');", UpdatePanel1);
            return;
        }

        msg = "" + msg + "，回复T退订";

        string phones = tbphones.Text.Trim();

        string[] phonelist = phones.Replace("\n",",").Split(',');
        if (phones.Length < 100)
        {
            AlertScript.AjaxRegisterScript("hideload_super();alert('手机号少于100，不能发送');", UpdatePanel1);
            return;
        }

        phones = WebUtility.dellast(phones.Replace("\n", ",").Trim());

        Hangjing.WebCommon.SendMsg.sendADSMS(phones, msg);


        AlertScript.AjaxRegisterScript("hideload_super();alert('发送成功');", UpdatePanel1);


    }

    /// <summary>
    /// 搜索用户
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void search_Click1(object sender, EventArgs e)
    {
        string SqlWhere = "1=1 and Custorder.delflag=0 ";

        if (tbStartTime.Text != "")
        {
            SqlWhere = SqlWhere + " and  custorder.OrderDateTime > '" + WebUtility.InputText(this.tbStartTime.Text) + "' ";
        }
        if (tbEndTime.Text != "")
        {
            SqlWhere = SqlWhere + " and  custorder.OrderDateTime <  '" + WebUtility.InputText(this.tbEndTime.Text) + " 23:59:59'";
        }
        if (DDLArea.SelectedValue != "0")
        {
            SqlWhere += " and custorder.cityid = " + DDLArea.SelectedValue + "";
        }
        if (tbTogoName.Text != "")
        {
            SqlWhere = SqlWhere + " and EXISTS (SELECT Unid FROM dbo.Points WHERE Unid = dbo.Custorder.TogoId AND Name LIKE '%" + WebUtility.InputText(tbTogoName.Text) + "%')";
        }

        string phones = WebUtility.dellast(new Custorder().searchPhone(SqlWhere));

        string[] phonelist = phones.Split(',');
        if (phones.Length < 100)
        {
            msgtip.Style["display"] = "";
            btSave.Enabled = false;
        }
        else
        {
            msgtip.Style["display"] = "none";
            btSave.Enabled = true; ;
        }

        phonecount.InnerText = "搜索到"+phonelist.Length+"个手机号";


        tbphones.Text =phones;

        AlertScript.AjaxRegisterScript("hideload_super();;", UpdatePanel1);

    }
    
}
